package com.disease.chronic.Exception;

import com.disease.chronic.Global.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(ChronicException.class)
    @ResponseBody
    public Result handleTiJianException(ChronicException e){
        e.printStackTrace();
        System.out.println(e.getMessage());
        return new Result(201,e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleException(Exception e){
        e.printStackTrace();
        System.out.println(e.getMessage());
        return new Result(ChronicExceptionEnum.SYSTEM_ERROR.getCode(), ChronicExceptionEnum.SYSTEM_ERROR.getMessage());
    }
}
